package com.last.controller;

import com.last.service.IHouseService;
import com.last.entity.HouseName;
import com.last.entity.PageDTO;
import com.last.entity.PageResult;
import com.last.entity.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private IHouseService iHouseService;

    @ApiOperation("查询所有民宿")
    @PostMapping("/findAll")
    public List<HouseName> findAll(){
        return iHouseService.findAll();
    }

    @ApiOperation("条件查询民宿+分页")
    @PostMapping("findAllByPage")
    public PageResult<HouseName> findAllByPage(@RequestBody PageDTO<HouseName> pageDTO){
        return iHouseService.findAllByPage(pageDTO);
    }

    @ApiOperation("保存或更新民宿信息")
    @PostMapping("/saveOrUpdate")
    public Result<HouseName> save(@RequestBody HouseName HouseName){
        Boolean b = iHouseService.saveOrUpdate(HouseName);
        return new Result(b,b?"保存成功":"保存失败");
    }

    @ApiOperation("删除单个民宿信息")
    @PostMapping("/del")
    public Result<HouseName> del(String homeId){

        int i = Integer.parseInt(homeId);
        return iHouseService.del(i);
    }
    @ApiOperation("删除多个民宿信息")
    @PostMapping("/delByIds")
    public Result<HouseName> delByIds(@RequestBody List<String> homeIds){
        Boolean b = iHouseService.removeByIds(homeIds);
        return new Result(b,b?"删除数据成功":"删除数据失败");
    }
//    @PostMapping("/update")
//    public Result<HouseName> update(@RequestBody HouseName HouseName){
//
//        return iHouseService.update(HouseName);
//    }
}
